package com.xyf.controller;

import com.seventh.common.pojo.R;
import com.xyf.pojo.entity.TbMaintainRecord;
import com.xyf.pojo.vo.MaintainRecordVo;
import com.xyf.service.TbMaintainRecordService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: clms-seventh
 * @description: 控制层
 * @author: 徐亚飞
 * @create: 2021-07-23 20:18
 **/
@RestController
@RequestMapping("safeguard/maintainRecord")
@Api(tags="维修记录控制层")
public class TbMaintainRecordController {
    @Autowired
    TbMaintainRecordService service;

    @PostMapping("/initMaintainRecordTable/{currentPage}/{pageSize}")
    @ApiOperation("分页查询维修记录")
    public R selectRecordByPage(@ApiParam(name = "currentPage", value = "页码", required = true) @PathVariable("currentPage")Integer currentPage,
                                @ApiParam(name = "pageSize", value = "每页多少条", required = true) @PathVariable("pageSize") Integer pageSize,
                                @ApiParam(name = "maintainRecordVo", value = "查询条件", required = false)       @RequestBody MaintainRecordVo maintainRecordVo
    ){
        return service.selectRecordByPage(currentPage,pageSize,maintainRecordVo);
    }

    @GetMapping("/selectById/{id}")
    @ApiOperation("根据Id查询查询维修记录")
    public TbMaintainRecord selectById(@ApiParam(name = "id", value = "维修ID", required = true)
                                           @PathVariable  Integer id){
        TbMaintainRecord tbMaintainRecord = service.selectById(id);
        return tbMaintainRecord;
    }


    @PostMapping("/insertMaintainRecord")
    @ApiOperation("添加维修记录")
    public R insertMaintainRecord(
            @ApiParam(name = "tbMaintainRecord", value = "维修记录的实体类", required = true)
            @RequestBody TbMaintainRecord tbMaintainRecord){
        System.out.println(tbMaintainRecord);
        return service.insertMaintainRecord(tbMaintainRecord);
    }

    @DeleteMapping("/deleteById/{id}")
    @ApiOperation("根据Id删除维修记录")
    public R deleteMaintainRecord(
            @ApiParam(name = "id", value = "维修ID", required = true)
            @PathVariable Integer id){
        return service.deleteMaintainRecord(id);
    }

    @PutMapping("/update")
    @ApiOperation("根据Id修改维修记录")
    public R updateMaintainRecord(
            @ApiParam(name = "tbMaintainRecord", value = "维修记录的实体类", required = true)
            @RequestBody TbMaintainRecord tbMaintainRecord){
        return service.updateMaintainRecord(tbMaintainRecord);
    }
}
